<?php
namespace Admin\Controller;
use Think\Controller;
use Myself\FileSystem;
use Admin\Controller\CommonController;
class JobwantController extends CommonController {

	protected $statusArr=array("下架","上架");
	protected $isHome=array("未推荐","已推荐");

    public function index(){
		header('Content-Type:text/html;charset=utf-8');
             
		//-----------------搜索-------------------
		$sh_q = I('sh_q','');//关键字
		if(!empty($sh_q)){
			$shArray['sh_q'] = $sh_q;
			$where['phone'] = array('LIKE','%'.$sh_q.'%');
		}
		

		$from_time = I('from_time','');
		$to_time = I('to_time','');
		  
		if($from_time){
			$from_time_s = strtotime($from_time);
			$where['addtime']= array('EGT',$from_time_s);
			$shArray['from_time'] = $from_time;
		}
		
		if($to_time){
			$to_time_s = strtotime($to_time)+86400;
			$where['addtime']= array('ELT',$to_time_s);
			$shArray['to_time'] = $to_time;	
		}		
		
		if($from_time && $to_time){
			$where['addtime']=array(array('EGT',$from_time_s),array('ELT',$to_time_s),'and');
		}	
			  
		if(!empty($shArray)){$this->assign('shArray',$shArray);}// 搜索参数输出
		//-------------------------搜索end-----------------

		$pageno = I('p',1);
                $pageCount = 10;
		$list = M('customer_jobwant')->where($where)->order('add_time desc, id desc')->page($pageno.','.$pageCount)->select();
		
		foreach($list as $key=>$item){
		$list[$key]['cus_id'] = M('customer')->where('cid="'.$item['cid'].'"')->getField('id');
                $list[$key]['fullname'] = M('customer_detail')->where('c_id="'.$list[$key]['cus_id'].'"')->getField('fullname');
	        $list[$key]['phone'] = M('customer')->where('cid="'.$item['cid'].'"')->getField('phone'); //customer_jobwant 加字段 phone   
			 
		}
             
	        $this->assign('list',$list);// 赋值数据集
		$count = M('customer_jobwant')->where($where)->count();// 查询满足要求的总记录数
		$this->assign('count',$count);// 赋值分页输出	
		$Page = new \Think\Page($count,$pageCount);// 实例化分页类 传入总记录数和每页显示的记录数
		$show = $Page->showAdmin();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出	
                $this->assign('statusArr',$this->statusArr);// 状态
		$this->display('Jobwant/index');
    }

 
	
	public function editJobwant(){
		header('Content-Type:text/html;charset=utf-8');
	        $id = I('id',0,'int');
		$dataInfo = M('customer_jobwant')->find($id);
		$cus_id = M('customer')->where('cid="'.$dataInfo['cid'].'"')->getField('id');
                $dataInfo['phone']= M('customer')->where('cid="'.$dataInfo['cid'].'"')->getField('phone');
                $dataInfo['fullname'] = M('customer_detail')->where('c_id="'.$cus_id .'"')->getField('fullname');
		$this->assign('dataInfo', $dataInfo);
	        $this->display('Jobwant/edit');
    }	
	
	
	  public function del(){

            $id = $_REQUEST['id'];
			
            if (is_array($id)){
               $where = 'id in('.implode(',', $id).')';
            } else {
               $where = 'id='.$id;
            }
			
            $list = M('customer_jobwant')->where($where)->delete();
	    $this->redirect('Jobwant/index');
            
    }

	
	 
	 
	 
	  
}